import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import '@fortawesome/fontawesome-free/css/all.css'
import { createActionCable } from './actionCable'
import store from './store'
import { setHeader } from './helpers/axios'

Vue.config.productionTip = false

// Setup axois for Vue.js
axios.defaults.baseURL = 'http://localhost:44300'
Vue.prototype.$http = axios

// Extensions
Vue.use(BootstrapVue)

// Event Bus
window.bus = new Vue()

window.chatwootPubsubToken = 'abc123456'

axios.get(`/api/v1/widget/configs?websiteToken=fea04126-22a6-43be-a1ad-302f5b948511&accountId=d062bd4e-2646-7b63-a740-3a08abcc6608`).then((res) => {
  console.log(res)
  const pubsubToken = res.data.pubsubToken
  const contactId = res.data.contactId
  const accountId = 'd062bd4e-2646-7b63-a740-3a08abcc6608'
  const authToken = res.data.authToken
  setHeader(authToken)
  window.chatwootWebChannel = res.data.webChannel
  window.WOOT_WIDGET = new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#app')
  window.WOOT_WIDGET.$store.dispatch('conversationAttributes/getAttributes')
  window.WOOT_WIDGET.actionCable = createActionCable(
    window.WOOT_WIDGET,
    pubsubToken,
    accountId,
    contactId,
    authToken
  )
})
